package org.holynite.fieldmanage.entities

import org.hibernate.annotations.GenericGenerator
import org.holynite.fieldmanage.types.DiscountConditionType
import org.holynite.fieldmanage.types.DiscountResultType

import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.Table

/**
 * Created by midnite on 15/1/4.
 */
@Entity
@Table(name = "commodity_discount_rule")
class CommodityDiscountRule implements Serializable {
	@Id
	@Column(name = "csr_id", nullable = false)
	@GeneratedValue(generator = "csr-gen")
	@GenericGenerator(name = "csr-gen", strategy = "uuid")
	String discountRuleId
	@Column(name = "belong_scheme")
	String belongToSchemeId
	@Enumerated(EnumType.STRING)
	@Column(name = "condition_type", nullable = false)
	DiscountConditionType conditionType = DiscountConditionType.Simple
	@Column(name = "limitation", nullable = false)
	Float limitation = 0
	@Enumerated(EnumType.STRING)
	@Column(name = "result_type", nullable = false)
	DiscountResultType resultType = DiscountResultType.DiscountPercent
	@Column(name = "discount", nullable = false)
	Float discount = 0

	boolean equals(o) {
		if (this.is(o)) return true
		if (getClass() != o.class) return false

		CommodityDiscountRule that = (CommodityDiscountRule) o

		if (discountRuleId != that.discountRuleId) return false

		return true
	}

	int hashCode() {
		return (discountRuleId != null ? discountRuleId.hashCode() : 0)
	}
}
